package cn.tedu.egweibo_02.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;
    //构造方法：针对没有具体数据返回的控制方法，比如添加资讯的方法，返回成功或失败信息即可
    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }
    //构造方法：针对有具体数据返回的控制方法，比如查询资讯的方法，返回成功信息以及数据即可
    public JsonResult(StatusCode statusCode,Object data){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public JsonResult ok(){
        return ok(null);
    }
}
